package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.NewDetailsRelatedBean;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

/**
 * 对象详情  相关 --adapter
 * <p>
 * Created by Administrator on 2017/9/6.
 */

public class NewDetailsRelateAdapter extends BaseRecyclerViewAdapter<NewDetailsRelatedBean.Rows> {


    public NewDetailsRelateAdapter(Context context) {
        super(context);
    }

    @Override
    public NewDetailsRelateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = inflater.inflate(R.layout.item_new_details_relate, null);
        return new NewDetailsRelateAdapter.NewDetailsRelateViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {
        NewDetailsRelateViewHolder holder = (NewDetailsRelateViewHolder) rholder;
        NewDetailsRelatedBean.Rows rows = mList.get(position);

        holder.tvTitleContent.setText(rows.getAssetName());//分类名称
        if (TextUtils.isEmpty(rows.getType())){
            holder.tvDepartment.setText(rows.getAssetSerial());
        }else{
            holder.tvDepartment.setText(rows.getAssetSerial()+"/"+rows.getTypeName());
        }

        //1:包含，2安装与运行关系
        if ("1".equals(rows.getType())) {
            holder.tvText.setText("包含");
        } else if ("2".equals(rows.getType())) {
            holder.tvText.setText("安装与运行关系");
        }

        //（硬件当时使用状态 0正常，1待检测，2维修，3借出，4报废,5闲置）
        if ("0".equals(rows.getCurStatus())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_76c56d);
            holder.button.setText("正常");
        } else if ("1".equals(rows.getCurStatus())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("待检测");
        } else if ("2".equals(rows.getCurStatus())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e9981f);
            holder.button.setText("维修");
        } else if ("3".equals(rows.getCurStatus())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e9981f);
            holder.button.setText("借出");
        } else if ("4".equals(rows.getCurStatus())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("报废");
        } else if ("5".equals(rows.getCurStatus())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_999691);
            holder.button.setText("闲置");
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(v,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }


    static class NewDetailsRelateViewHolder extends RecyclerView.ViewHolder {
        private View itemView;
        private TextView tvTitleContent;//标题内容
        private TextView tvDepartment;//部门
        private TextView tvText;//文字（包含、正常）
        private Button button;//状态按钮

        public NewDetailsRelateViewHolder(View view) {
            super(view);
            itemView = view;
            tvTitleContent = itemView.findViewById(R.id.tv_title_content);
            tvDepartment = itemView.findViewById(R.id.tv_department);
            tvText = itemView.findViewById(R.id.tv_text);
            button = itemView.findViewById(R.id.button);
        }
    }

}
